home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWPoint.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  11.9 KB  |  463 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPoint.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWPOINT_H
  13. #include "FWPoint.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWSTREAM_H
  21. #include "FWStream.h"
  22. #endif
  23.  
  24. // ----- OpenDoc Includes -----
  25.  
  26. #ifndef _XMPTYPES_
  27. #include <XMPTypes.h>
  28. #endif
  29.  
  30. // ----- Macintosh Includes -----
  31. #if defined(FW_BUILD_MAC) && !defined(__FIXMATH__)
  32. #include <FixMath.h>
  33. #endif
  34.  
  35. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  36. #include <math routines.h>
  37. #endif
  38.  
  39. //==============================================================================
  40. //    •• RunTime Info
  41. //==============================================================================
  42.  
  43. #ifdef FW_BUILD_MAC
  44. #pragma segment fwgraphx
  45. #endif
  46.  
  47. //==============================================================================
  48. //    •• struct FW_CPoint
  49. //==============================================================================
  50.  
  51. //------------------------------------------------------------------------------
  52. //    • FW_CPoint::FW_CPoint
  53. //------------------------------------------------------------------------------
  54.  
  55. FW_CPoint::FW_CPoint(FW_SPlatformPoint plfmPoint)
  56. {
  57. #ifdef FW_BUILD_MAC
  58.     x = ff(plfmPoint.h);
  59.     y = ff(plfmPoint.v);
  60. #endif
  61.  
  62. #ifdef FW_BUILD_WIN
  63. #endif
  64. }
  65.  
  66. //------------------------------------------------------------------------------
  67. //    • FW_CPoint::FW_CPoint
  68. //------------------------------------------------------------------------------
  69. FW_CPoint::FW_CPoint(const FW_CPoint &pt)
  70. {
  71.     x = pt.x;
  72.     y = pt.y;
  73. }
  74.  
  75. //------------------------------------------------------------------------------
  76. //    • FW_CPoint::FW_CPoint
  77. //------------------------------------------------------------------------------
  78. FW_CPoint::FW_CPoint(const XMPPoint &xmpPoint)
  79. {
  80.     x = xmpPoint.x;
  81.     y = xmpPoint.y;
  82. }
  83.  
  84. //------------------------------------------------------------------------------
  85. //    • FW_CPoint::operator=
  86. //------------------------------------------------------------------------------
  87.  
  88. FW_CPoint& FW_CPoint::operator=(const FW_CPoint &pt)
  89. {
  90.     x = pt.x;
  91.     y = pt.y;
  92.     return *this;
  93. }
  94.  
  95. //------------------------------------------------------------------------------
  96. //    • FW_CPoint::operator=
  97. //------------------------------------------------------------------------------
  98.  
  99. FW_CPoint& FW_CPoint::operator=(const XMPPoint &xmpPoint)
  100. {
  101.     x = xmpPoint.x;
  102.     y = xmpPoint.y;
  103.     return *this;
  104. }
  105.  
  106. //------------------------------------------------------------------------------
  107. //    • FW_CPoint::operator=
  108. //------------------------------------------------------------------------------
  109.  
  110. FW_CPoint& FW_CPoint::operator=(FW_SPlatformPoint plfmPoint)
  111. {
  112. #ifdef FW_BUILD_MAC
  113.     x = ff(plfmPoint.h);
  114.     y = ff(plfmPoint.v);
  115. #endif
  116.  
  117. #ifdef FW_BUILD_WIN
  118. #endif
  119.  
  120.     return *this;
  121. }
  122.  
  123. //------------------------------------------------------------------------------
  124. //    • FW_CPoint::Offset
  125. //------------------------------------------------------------------------------
  126.  
  127. void FW_CPoint::Offset(XMPCoordinate xx, XMPCoordinate yy)
  128. {
  129.     x += xx;
  130.     y += yy;
  131. }
  132.  
  133. //------------------------------------------------------------------------------
  134. //    • FW_CPoint::operator+=
  135. //------------------------------------------------------------------------------
  136.  
  137. FW_CPoint& FW_CPoint::operator+=(const FW_CPoint &pt)
  138. {
  139.     x += pt.x;
  140.     y += pt.y;
  141.     return *this;
  142. }
  143.  
  144. //------------------------------------------------------------------------------
  145. //    • FW_CPoint::operator-=
  146. //------------------------------------------------------------------------------
  147.  
  148. FW_CPoint& FW_CPoint::operator-=(const FW_CPoint &pt)
  149. {
  150.     x -= pt.x;
  151.     y -= pt.y;
  152.     return *this;
  153. }
  154.  
  155. //------------------------------------------------------------------------------
  156. //    • FW_CPoint::operator+=
  157. //------------------------------------------------------------------------------
  158.  
  159. FW_CPoint& FW_CPoint::operator+=(const XMPPoint &xmpPoint)
  160. {
  161.     x += xmpPoint.x;
  162.     y += xmpPoint.y;
  163.     return *this;
  164. }
  165.  
  166. //------------------------------------------------------------------------------
  167. //    • FW_CPoint::operator-=
  168. //------------------------------------------------------------------------------
  169.  
  170. FW_CPoint& FW_CPoint::operator-=(const XMPPoint &xmpPoint)
  171. {
  172.     x -= xmpPoint.x;
  173.     y -= xmpPoint.y;
  174.     return *this;
  175. }
  176.  
  177. //------------------------------------------------------------------------------
  178. //    • FW_CPoint::operator+
  179. //------------------------------------------------------------------------------
  180.  
  181. FW_CPoint FW_CPoint::operator+(const FW_CPoint &pt) const
  182. {
  183.     FW_CPoint returnPt;
  184.     returnPt.x = x + pt.x;
  185.     returnPt.y = y + pt.y;
  186.     return returnPt;
  187. }
  188.  
  189. //------------------------------------------------------------------------------
  190. //    • FW_CPoint::operator-
  191. //------------------------------------------------------------------------------
  192.  
  193. FW_CPoint FW_CPoint::operator-(const FW_CPoint &pt) const
  194. {
  195.     FW_CPoint returnPt;
  196.     returnPt.x = x - pt.x;
  197.     returnPt.y = y - pt.y;
  198.     return returnPt;
  199. }
  200.  
  201. //------------------------------------------------------------------------------
  202. //    • FW_CPoint::operator+
  203. //------------------------------------------------------------------------------
  204.  
  205. FW_CPoint FW_CPoint::operator+(const XMPPoint &xmpPoint) const
  206. {
  207.     FW_CPoint returnPt;
  208.     returnPt.x = x + xmpPoint.x;
  209.     returnPt.y = y + xmpPoint.y;
  210.     return returnPt;
  211. }
  212.  
  213. //------------------------------------------------------------------------------
  214. //    • FW_CPoint::operator-
  215. //------------------------------------------------------------------------------
  216.  
  217. FW_CPoint FW_CPoint::operator-(const XMPPoint &xmpPoint) const
  218. {
  219.     FW_CPoint returnPt;
  220.     returnPt.x = x - xmpPoint.x;
  221.     returnPt.y = y - xmpPoint.y;
  222.     return returnPt;
  223. }
  224.  
  225. //------------------------------------------------------------------------------
  226. //    • FW_CPoint::operator-
  227. //------------------------------------------------------------------------------
  228.  
  229. FW_CPoint FW_CPoint::operator-() const
  230. {
  231.     FW_CPoint returnPt;
  232.     returnPt.x = -x;
  233.     returnPt.y = -y;
  234.     return returnPt;
  235. }
  236.  
  237. //------------------------------------------------------------------------------
  238. //    • FW_CPoint::operator+=
  239. //------------------------------------------------------------------------------
  240.  
  241. FW_CPoint& FW_CPoint::operator+=(FW_SPlatformPoint plfmPoint)
  242. {
  243. #ifdef FW_BUILD_MAC
  244.     x += ff(plfmPoint.h);
  245.     y += ff(plfmPoint.v);
  246. #endif
  247.  
  248. #ifdef FW_BUILD_WIN
  249. #endif
  250.  
  251.     return *this;
  252. }
  253.  
  254. //------------------------------------------------------------------------------
  255. //    • FW_CPoint::operator-=
  256. //------------------------------------------------------------------------------
  257.  
  258. FW_CPoint& FW_CPoint::operator-=(FW_SPlatformPoint plfmPoint)
  259. {
  260. #ifdef FW_BUILD_MAC
  261.     x -= ff(plfmPoint.h);
  262.     y -= ff(plfmPoint.v);
  263. #endif
  264.  
  265. #ifdef FW_BUILD_WIN
  266. #endif
  267.  
  268.     return *this;
  269. }
  270.  
  271. //------------------------------------------------------------------------------
  272. //    • FW_CPoint::operator+
  273. //------------------------------------------------------------------------------
  274.  
  275. FW_CPoint FW_CPoint::operator+(FW_SPlatformPoint plfmPoint) const
  276. {
  277.     FW_CPoint returnPt;
  278.     
  279. #ifdef FW_BUILD_MAC
  280.     returnPt.x  = x + ff(plfmPoint.h);
  281.     returnPt.y  = y + ff(plfmPoint.v);
  282. #endif
  283.  
  284. #ifdef FW_BUILD_WIN
  285. #endif
  286.  
  287.     return returnPt;
  288. }
  289.  
  290. //------------------------------------------------------------------------------
  291. //    • FW_CPoint::operator-
  292. //------------------------------------------------------------------------------
  293.  
  294. FW_CPoint FW_CPoint::operator-(FW_SPlatformPoint plfmPoint) const
  295. {
  296.     FW_CPoint returnPt;
  297.     
  298. #ifdef FW_BUILD_MAC
  299.     returnPt.x  = x - ff(plfmPoint.h);
  300.     returnPt.y  = y - ff(plfmPoint.v);
  301. #endif
  302.  
  303. #ifdef FW_BUILD_WIN
  304. #endif
  305.  
  306.     return returnPt;
  307. }
  308.  
  309. //------------------------------------------------------------------------------
  310. //    • FW_CPoint::opertor FW_SPlatformPoint const
  311. //------------------------------------------------------------------------------
  312.  
  313. FW_CPoint::operator FW_SPlatformPoint() const
  314. {
  315.     FW_SPlatformPoint plfmPoint;
  316.     
  317. #ifdef FW_BUILD_MAC
  318.     plfmPoint.h = FixedToInt(x);
  319.     plfmPoint.v = FixedToInt(y);
  320. #endif
  321.  
  322. #ifdef FW_BUILD_WIN
  323. #endif
  324.  
  325.     return plfmPoint;
  326. }
  327.  
  328. //------------------------------------------------------------------------------
  329. //    • FW_CPoint::AsPlatformPoint
  330. //------------------------------------------------------------------------------
  331.  
  332. void FW_CPoint::AsPlatformPoint(FW_SPlatformPoint& plfmPoint) const
  333. {
  334. #ifdef FW_BUILD_MAC
  335.     plfmPoint.h = FixedToInt(x);
  336.     plfmPoint.v = FixedToInt(y);
  337. #endif
  338.  
  339. #ifdef FW_BUILD_WIN
  340. #endif
  341. }
  342.  
  343. //------------------------------------------------------------------------------
  344. //    • FW_CPoint::IntX
  345. //------------------------------------------------------------------------------
  346.  
  347. short FW_CPoint::IntX() const
  348. {
  349. #ifdef FW_BUILD_MAC
  350.     return FixedToInt(x);
  351. #endif
  352.  
  353. #ifdef FW_BUILD_WIN
  354. #endif
  355. }
  356.  
  357. //------------------------------------------------------------------------------
  358. //    • FW_CPoint::IntY
  359. //------------------------------------------------------------------------------
  360.  
  361. short FW_CPoint::IntY() const
  362. {
  363. #ifdef FW_BUILD_MAC
  364.     return FixedToInt(y);
  365. #endif
  366.  
  367. #ifdef FW_BUILD_WIN
  368. #endif
  369. }
  370.  
  371. //------------------------------------------------------------------------------
  372. //    • FW_CPoint::operator==
  373. //------------------------------------------------------------------------------
  374.  
  375. FW_Boolean FW_CPoint::operator==(const FW_CPoint &pt) const
  376. {
  377.     return x==pt.x && y==pt.y;
  378. }
  379.  
  380. //------------------------------------------------------------------------------
  381. //    • FW_CPoint::operator!=
  382. //------------------------------------------------------------------------------
  383.  
  384. FW_Boolean FW_CPoint::operator!=(const FW_CPoint &pt) const
  385. {
  386.     return x!=pt.x || y!=pt.y;
  387. }
  388.  
  389. //------------------------------------------------------------------------------
  390. //    • FW_CPoint::operator==
  391. //------------------------------------------------------------------------------
  392.  
  393. FW_Boolean FW_CPoint::operator==(const XMPPoint &xmpPoint) const
  394. {
  395.     return x==xmpPoint.x && y==xmpPoint.y;
  396. }
  397.  
  398. //------------------------------------------------------------------------------
  399. //    • FW_CPoint::operator!=
  400. //------------------------------------------------------------------------------
  401.  
  402. FW_Boolean FW_CPoint::operator!=(const XMPPoint &xmpPoint) const
  403. {
  404.     return x!=xmpPoint.x || y!=xmpPoint.y;
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    • FW_CPoint::operator[]
  409. //----------------------------------------------------------------------------------------
  410.  
  411. XMPCoordinate& FW_CPoint::operator[](FW_XYSelector selector)
  412. {
  413.     return selector == FW_kVertical ? y : x;
  414. }
  415.  
  416. //----------------------------------------------------------------------------------------
  417. //    • FW_CPoint::operator[]
  418. //----------------------------------------------------------------------------------------
  419.  
  420. XMPCoordinate FW_CPoint::operator[](FW_XYSelector selector) const
  421. {
  422.     return selector == FW_kVertical ? y : x;
  423. }
  424.  
  425. //----------------------------------------------------------------------------------------
  426. //    • FW_CPoint::Map
  427. //----------------------------------------------------------------------------------------
  428.  
  429. void FW_CPoint::Map(const FW_CRect& srcRect, const FW_CRect& destRect)
  430. {
  431.     FW_CPoint delta;
  432.     delta.x = x - srcRect.left;
  433.     delta.y = y - srcRect.top;
  434.     
  435.     delta.x = ::FixDiv(delta.x * destRect.Width(), srcRect.Width());
  436.     delta.y = ::FixDiv(delta.y * destRect.Height(), srcRect.Height());
  437.     
  438.     x = destRect.left + delta.x;
  439.     y = destRect.top + delta.y;
  440. }
  441.  
  442. //----------------------------------------------------------------------------------------
  443. //    • FW_CPoint::Flatten
  444. //----------------------------------------------------------------------------------------
  445.  
  446. void FW_CPoint::Flatten(FW_CWritableStream& stream)
  447. {
  448.     stream.Write((char*)this, sizeof(XMPPoint));
  449. }
  450.  
  451. //----------------------------------------------------------------------------------------
  452. //    • FW_CPoint::Unflatten
  453. //----------------------------------------------------------------------------------------
  454.  
  455. void FW_CPoint::Unflatten(FW_CReadableStream& stream)
  456. {
  457.     stream.Read((char*)this, sizeof(XMPPoint));
  458. }
  459.  
  460.  
  461.  
  462.  
  463.